﻿Tracking3DAppView = function () {
    Sim.App.call(this);

};

Tracking3DAppView.prototype = new Sim.App();

Tracking3DAppView.prototype.init = function (param) {
    this.trackingLine2Ds = [];
    this.axises = [];
    Sim.App.prototype.init.call(this, param);
    this.renderer.setClearColor(0x008080);
    this.camera.position.set(0, 0, 200);
    this.controls = new THREE.TrackballControls(this.camera, this.renderer.domElement);
};

Tracking3DAppView.prototype.show = function (groupPoints) {
    Tracking3DAppView.Geometries = [];
    if (this.trackingLine2Ds) {
        for (var i = 0; i < this.trackingLine2Ds.length; i++) {
            this.doDispose(this.trackingLine2Ds[i]);
        }
        this.trackingLine2Ds = [];
    }
    if (this.axises) {
        for (i = 0; i < this.axises.length; i++) {
            this.doDispose(this.axises[i]);
        }
        this.axises = [];
    }

    var xy = new THREE.Vector3(1, 1, 0);
    var xz = new THREE.Vector3(1, 0, 1);
    var yz = new THREE.Vector3(0, 1, 1);
    var axisXY = this.createXYZ2D(xy, groupPoints, extremeVs);
    var axisXZ = this.createXYZ2D(xz, groupPoints, extremeVs);
//    axisXZ.object3D.rotation.x -= Math.PI / 2;
//    axisXZ.object3D.position.x -= 300;
//    axisXZ.object3D.position.y -= 20;
    var axisYZ = this.createXYZ2D(yz, groupPoints, extremeVs);
//    axisYZ.object3D.rotation.y += Math.PI / 2;
    this.addObject(axisXY);
    this.addObject(axisXZ);
    this.addObject(axisYZ);
};

Tracking3DAppView.prototype.createXYZ2D = function (xyz, groupPoints, extremeVs) {
    var maxV = new THREE.Vector3(-1000, -1000, -1000);
    var minV = new THREE.Vector3(1000, 1000, 1000);
    for (var i = 0; i < extremeVs.length; i++) {
        maxV.max(extremeVs[i].max);
        minV.min(extremeVs[i].min);
    }

    minV.multiply(xyz);
    maxV.multiply(xyz);
    var axis = new Axis2D();
    axis.init(groupPoints, maxV, minV, Tracking3DAppView.STEP, effectController, xyz);
    this.axises.push(axis);
    return axis;
};

Tracking3DAppView.prototype.update = function () {
    Sim.App.prototype.update.call(this);
   
    this.controls.update();
};

//步履,每10作为坐标轴的1.
Tracking3DAppView.STEP = 10;

Tracking3DAppView.Geometries = [];